package ren.edu.apollo.controller;

import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PackageName: ren.edu.apollo.controller
 * @ClassName: ApolloSpringAnnotationConfigController
 * @Description:
 * @author: RZS
 * @date: 2021/7/17  22:30
 */
@RestController
@RequestMapping("/apollo-config")
public class ApolloSpringAnnotationConfigController {

    // @ApolloConfig用来自动注入 Apollo Config
    @ApolloConfig
    private Config config;

    @GetMapping("/username-config")
    public String usernameRedisConfig(){
        /**
         * config.getProperty(配置中心的key, 读取失败时获取此默认值)
         */
        return config.getProperty("username", "null") + "<=======>" +
                config.getProperty("redis.cache.host", "null");
    }
}
